package com.ebupt.migu.music.commons.selfdom.demo.impl;

import com.ebupt.migu.globalpopup.entity.ConditionRelation;
import com.ebupt.migu.globalpopup.enums.ConditionEnum;
import com.ebupt.migu.music.commons.selfdom.demo.Login;
import com.ebupt.migu.music.commons.selfdom.demo.impl.identifier.AbstractIdentifierImpl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 登录子条件实现类
 *
 * @author wangzhu
 * @since 2021-12-31
 */
public class LoginImpl extends AbstractIdentifierImpl implements Login {
    /**
     * 登录
     */
    private boolean loginIng(Object data, ConditionRelation conditionRelation,Integer conditionKey) {
        return data!=null&&!data.equals("")? true : false;
    }

    /**
     * 未登录
     */
    private boolean notLogIn(Object data, ConditionRelation conditionRelation,Integer conditionKey) {
        return data!=null&&!data.equals("")? false : true;
    }

    /**
     * 更具不同的子条件判断返回判断结果（子条件第一版只支持or）
     */
    @Override
    public boolean getLogin(Map data, List<ConditionRelation> conditionRelations) {

        LinkedHashMap<Boolean, Integer> booleanIntegerLinkedHashMap = new LinkedHashMap<>();
        // 排序
        super.sort(conditionRelations);
        for (ConditionRelation conditionRelation : conditionRelations) {
            boolean login = true;
            //特殊配置登录获取uid
            Object value = data.get(ConditionEnum.getKeyValue(2,1));

            switch (conditionRelation.getConditionKey()) {
                case 1:
                    login = this.loginIng(value, conditionRelation,conditionRelation.getConditionKey());
                    break;
                case 2:
                    login = this.notLogIn(value, conditionRelation,conditionRelation.getConditionKey());
                    break;
                default:
                    break;
            }
            booleanIntegerLinkedHashMap.put(login, conditionRelation.getCConnector());
        }
        return super.getRelation(booleanIntegerLinkedHashMap);
    }


}
